package com.GLM.Tools.DB;


import com.GLM.Constants.Constant;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelpter extends SQLiteOpenHelper {

	private static DatabaseHelpter mInstance = null;

	private DatabaseHelpter(Context context) {
		super(context, Constant.DATABASE_NAME, null, Constant.DATABASE_VERSION);
	}

	public static synchronized DatabaseHelpter getInstance(Context context) {
		if (mInstance == null) {
			mInstance = new DatabaseHelpter(context);
		}
		return mInstance;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String CREATE_TABLE_USERINFO = "create table " 
				+ Constant.TABLE_USERINFO + "(" + Constant.COLUMN_USERID
				+ " INTEGER PRIMARY KEY, " + Constant.COLUMN_USERACCOUNT
				+ " TEXT, " + Constant.COLUMN_PASSWORD + " TEXT, "
				+ Constant.COLUMN_NICKNAME + " TEXT, " + Constant.COLUMN_EMAIL
				+ " TEXT, "
				+ Constant.COLUMN_LATITUDE + " REAL, "
				+ Constant.COLUMN_LONGITUDE + " REAL, "
				+ Constant.COLUMN_USERAVATARURL + " TEXT,"
				+ Constant.COLUMN_USERAVATAR + " BLOB)";

		db.execSQL(CREATE_TABLE_USERINFO);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}

	public boolean deleteDatabase(Context context) {
		return context.deleteDatabase(Constant.DATABASE_NAME);
	}
	
	
}
